<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org"
      xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head th:include="include :: header"></head>
<body class="hold-transition skin-blue sidebar-mini">

<section class="content-header">
    <h1>派工领料计划提交</h1>
</section>
<section class="content">
    <div class="row">
        <div class="col-xs-12">
            <div class="box">
                <div class="box-header">
                    <form id="queryForm" onsubmit="return false;">
                        <div class="row">
                            <div class="form-inline">
                                <div class="form-group">
                                    <label for="query-prodNo">生产令号</label>
                                    <input id="query-prodNo" type="text" name="prodNo" class="form-control"
                                           placeholder="请输入生产令号">
                                </div>
                                <div class="form-group">
                                    <label for="query-proName">项目名称</label>
                                    <input id="query-proName" type="text" name="proName" class="form-control"
                                           placeholder="请输入项目名称">
                                </div>
                                <div class="form-group">
                                    <label for="query-part">部分</label>
                                    <input id="query-part" type="text" name="part" class="form-control"
                                           placeholder="请输入部分">
                                </div>
                                <div class="form-group">
                                    <label for="query-drawNo">派工图号</label>
                                    <input id="query-drawNo" type="text" name="drawNoDis" class="form-control"
                                           placeholder="请输入派工图号">
                                </div>
                                <div class="form-group">
                                    <label for="query-drawName">派工图名</label>
                                    <input id="query-drawName" type="text" name="drawNameDis" class="form-control"
                                           placeholder="请输入派工图名">
                                </div>
                                <div class="form-group">
                                    <label for="query-status">状态</label>
                                    <select id="query-status" class="form-control" name="status">
                                        <option value="">请选择</option>
                                        <option value="1" selected>未提交</option>
                                        <option value="2">已提交</option>
                                    </select>
                                </div>
                                <button type="button" class="btn btn-success" id="btn-search"
                                        onclick="js.table.search(table)">
                                    <span class="Bold">搜索</span>
                                </button>
                            </div>
                        </div>
                    </form>
                </div>
                <div class="box-body">
                    <div class="row" id="toolbar">
                        <div class="form-inline">
                            <button shiro:hasPermission="asseOrd:makeSub:submit" type="button" class="btn btn-info" id="btn-sub"> 提交</button>
                        </div>
                    </div>
                    <table id="bootstrap-table"></table>
                </div>
            </div>
        </div>
    </div>
</section>
<div th:include="include :: footer"></div>
<script th:inline="javascript">

    let table;

    /** 删除 */
    function del(rowData) {
        js.confirmPost({
            content: "确定删除选中的装配零件吗？",
            url: ctx + "assemble/assMake/delMake",
            data: {arrIds: rowData.id, sheetId: rowData.sheetId},
            success: function (result) {
                if (result.type === web_status.SUCCESS) {
                    js.modal.success(result.msg);
                } else {
                    js.modal.warning("被提交的数据不允许删除，请刷新页面后重新选择要删除的数据！");
                }
                js.table.refresh(table);
            }
        })
    }

    /** 撤销 */
    function cancel(id) {
        js.modal.confirm("确定撤销选中的装配零件吗？", function () {
            js.post({
                url: ctx + "assemble/assMake/cancel",
                data: {id: id},
                success: function (result) {
                    if (result.type === web_status.SUCCESS) {
                        js.modal.success(result.msg);
                        js.table.refresh(table);
                    } else {
                        js.modal.warning(result.msg);
                    }
                }
            })
        })
    }

    $(function () {

        /** 加载列表 */
        table = js.table.init({
            url: ctx + "assemble/assMake/makeListAll",
            showColumns: true,
            showExport: true,
            columns: [

                {
                    field: "checked",
                    title: '全选',
                    checkbox: true,
                    formatter: function (value, row, index) {
                        if (row.status === 1 && row.minusFlg === 0) {
                            return {
                                disabled: false
                            }
                        } else {
                            return {
                                disabled: true
                            }
                        }
                    }
                },
                {
                    title: '序号', field: 'id', width: '50',
                    formatter: function (value, row, index) {
                        return index + 1;
                    }
                },
                {title: "生产令号", field: 'prodNo'},
                {title: "项目名称", field: 'proName'},
                {title: "类型", field: 'special'},
                {title: "部分", field: 'part'},
                {title: "派工图号", field: 'drawNoDis'},
                {title: "派工图名", field: 'drawNameDis'},
                {title: "零件图号", field: 'drawNo'},
                {title: "零件图名", field: 'drawName'},
                {title: "使用数量", field: 'useNum'},
                {
                    title: "提交状态", field: 'status',
                    formatter: function (value, row) {
                        if (value === 1) {
                            return '<span class="badge label-inverse">未提交</span>';
                        } else if (value === 2) {
                            return '<span class="badge label-success">已提交</span>';
                        }
                    }
                },
                {
                    title: "操作", width: '110',
                    formatter: function (value, row) {
                        let actions = [];
                        actions.push('<a class="btn btn-info btn-xs" target="_blank" href="' + ctx + 'assemble/assMake/makeView/' + row.sheetId + '" > 查看</a>');
                        if (hasP('asseOrd:makeSub:del') && row.status == 1 && sessionUser.account === row.createCode) {
                            actions.push('<a class="btn btn-danger btn-xs" href="javascript:void(0)" onclick="del(' + js.jsonStringify(row) + ')"> 删除</a> ');
                        }
                        if (hasP('asseOrd:makeSub:regit') && row.status == 2 && sessionUser.account === row.createCode) {
                            actions.push('<a class="btn btn-danger btn-xs" href="javascript:void(0)" onclick="cancel(' + row.id + ')"> 撤销</a>');
                        }
                        return actions.join('');
                    }
                }
            ],
            rowStyle: function (row, index) {
                if (row.minusFlg == 1) {
                    return {css: {"color": "red"}}
                } else {
                    return {css: {"color": "black"}}
                }
            }
        });

        /** 批量提交 */
        $("#btn-sub").click(function () {
            var rows = js.table.selectRows("bootstrap-table");
            // 如果没有选择，显示提示信息
            if (rows.length == 0) {
                js.modal.warning("请至少选择一条明细");
                return false;
            } else {
                let arr = js.table.selectColumns(table, "id");
                let arrIds = arr.join(',');
                js.confirmPost({
                    content: "确定提交选中的装配零件吗？",
                    url: ctx + "assemble/assMake/subMake",
                    data: {arrIds: arrIds},
                    success: function (result) {
                        if (result.type === web_status.SUCCESS) {
                            js.modal.success(result.msg);
                        } else {
                            js.modal.warning(result.msg);
                        }
                        js.table.refresh(table);
                    }
                })
            }
        });

    });
</script>
</body>
</html>
